<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Http\Controllers\Xwam;

/**
 * Description of Login
 *
 * @author SoChishun
 */
class Login extends \App\Http\Controllers\Controller {

    public function index() {
        $data= \App\Model\User\AdminModel::find(1);
        var_export($data);
        return view('xwam/login/index', ['showCaptcha' => true]);
    }

    public function doLogin(\Illuminate\Http\Request $request) {
        // 用户输入验证
        $rules = [
            'loginid' => 'required|max:2',
            'password' => 'required|max:32',
            'captcha' => 'required|captcha',
        ];
        $messages = [
            'loginid.required' => '用户名未填写',
            'loginid.max' => '用户名无效',
            'password.required' => '密码未填写',
            'password.max' => '密码无效',
            'captcha.required' => '验证码未填写',
            'captcha.captcha' => '验证码错误',
        ];
        $validator = \Validator::make($request->all(), $rules, $messages);
        if ($validator->fails()) {
            return ['success' => false, 'message' => $validator->errors()->all()];
        }
        // 数据库验证
        return ['success' => true, 'message' => '/index/index'];
    }

}
